package com.lee.mybatis;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.lee.mybatis.mappers.StudentMapper;

/**
 * Hello world!
 *
 */
public class App {
	public static void main(String[] args) {
		// 使用xml配置方式访问
		String resource = "demo-mybatis-config.xml";
		InputStream inputStream;
		try {
			inputStream = Resources.getResourceAsStream(resource);
			SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
			try (SqlSession session = sessionFactory.openSession()) {
				StudentMapper studentMapper = session.getMapper(StudentMapper.class);
				Student student = studentMapper.selectStudent(1);
				System.out.println(student);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
